<template>
  <div>
    <common-head title="修改联系人" bg="#908"/>
    <div class="main">
      <van-address-edit
        :area-list="areaInfo"
        show-postal
        show-set-default
        :address-info="addressInfo"
        :area-columns-placeholder="['省', '市', '区']"
        @save="onSave"
      />
    </div>
  </div>
</template>

<script>
import CommonHead from '@components/CommonHead'
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      addressInfo: {}
    }
  },
  created () {
    this.initAddressInfo()
  },
  methods: {
    initAddressInfo () {
      // 初始化 默认地址
      this.addressInfo = this.contacts[parseInt(this.$route.params.index)]
    },
    onSave (address) {
      console.log(address)
      this.editContact({ contact: address, index: parseInt(this.$route.params.index) })
      // 新增联系人
      this.$toast('修改成功')
      this.$router.go(-1)
    },
    ...mapMutations(['editContact'])
  },
  computed: {
    ...mapState(['areaInfo', 'contacts'])
  },
  components: {
    CommonHead
  }
}
</script>

<style lang="scss" scoped>

</style>
